package com.cloudsigns.factorymanager2.produce.fragment.produce_team;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.engineering.customview.AddProductInforPoupWindow;
import com.cloudsigns.factorymanager2.project.customview.GeneralPurposePoupWindow;
import com.cloudsigns.factorymanager2.project.myinerface.ItemClickListener;

public class ProduceTeamStatisticalFragment extends Fragment implements View.OnClickListener,ItemClickListener {
    private TextView edit_query_type,edit_query_month;
    private View v_query_type,v_query_month;
    private ImageView img_query_type,img_query_month;
    private RelativeLayout rl_query;

    private GeneralPurposePoupWindow generalPurposePoupWindow;
    private String types[] = {"加工汇总", "交接汇总","计件统计","异常统计"};
    private AddProductInforPoupWindow addProductInforPoupWindow;
    private String months[] = {"1月", "2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"};

    private String clickType;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_produce_team_statistical,null);
        edit_query_type=view.findViewById(R.id.edit_query_type);
        v_query_type=view.findViewById(R.id.v_query_type);
        img_query_type=view.findViewById(R.id.img_query_type);
        edit_query_month=view.findViewById(R.id.edit_query_month);
        v_query_month=view.findViewById(R.id.v_query_month);
        img_query_month=view.findViewById(R.id.img_query_month);
        rl_query=view.findViewById(R.id.rl_query);

        img_query_type.setOnClickListener(this);
        img_query_month.setOnClickListener(this);
        rl_query.setOnClickListener(this);
        return view;
    }

    // 查询类型
    private void showSearchTypesWindow(View anchor) {
        generalPurposePoupWindow = new GeneralPurposePoupWindow(getActivity(), types);
        generalPurposePoupWindow.setItemClick(this);
        generalPurposePoupWindow.showPopupWindow(anchor);
    }

    // 查询月份
    private void showSearchMonthsWindow(View anchor){
        addProductInforPoupWindow = new AddProductInforPoupWindow(getActivity(), months);
        addProductInforPoupWindow.setItemClick(this);
        addProductInforPoupWindow.showPopupWindow(anchor);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            // 查询类型
            case R.id.img_query_type:
                showSearchTypesWindow(v_query_type);
                clickType="types";
                break;
                // 查询月份
            case R.id.img_query_month:
                showSearchMonthsWindow(v_query_month);
                clickType="month";
                break;
                // 保存
            case R.id.rl_query:
                break;
        }
    }

    @Override
    public void itemClick(View view, int position) {
        if ("types".equals(clickType)){
            edit_query_type.setText(types[position]);
        } else if ("month".equals(clickType)){
            edit_query_month.setText(months[position]);
        }
    }
}
